{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d82d93c-7fcc-4548-9526-2451b60b2f4f",
   "metadata": {},
   "source": [
    "Chapter 09\n",
    "# 定义、使用“鸡”类，创建实例时不需要参数\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6835620c-a72c-44a7-a5d7-9c880949d5bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建了一个名为 \"Chicken\" 的类\n",
    "class Chicken:\n",
    "    def __init__(self):\n",
    "    # 初始化对象的属性\n",
    "        # 设置实例变量self.name来存储小鸡名字的参数\n",
    "        self.name = ''\n",
    "        # 设置实例变量self.age来存储小鸡名字的年龄\n",
    "        self.age = ''\n",
    "        # 设置实例变量self.color来存储小鸡名字的颜色\n",
    "        self.color = ''\n",
    "        # 设置实例变量self.weight来存储小鸡名字的体重\n",
    "        self.weight = ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bacad8f3-3d9f-4b48-a44f-57dd7a41ebca",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用Chicken类，然后赋值\n",
    "chicken_01 = Chicken()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7a46b1db-c5dd-4950-9236-2c1b13035b4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "chicken_01.name = '小红'\n",
    "chicken_01.age = 1\n",
    "chicken_01.color = '黄色'\n",
    "chicken_01.weight = 1.5"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
